/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package learn.qual;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
/**
 *
 * @author robit
 */
public class Snapper {
   static boolean  test(int N,int K){
      int nradix=(int) Math.pow(2,N);
      return K%nradix==(nradix-1);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        Scanner s = null;
        PrintWriter o = null;
        try {
            s = new Scanner(
                    new BufferedReader(new FileReader("A-large-practice.in")));
            //s.useLocale(Locale.US);
            o =
            new PrintWriter(new BufferedWriter(new FileWriter("A-large-output.in")));

            int size = s.nextInt();
            for (int i =1; i <=size ; i++) {
                String answer=test(s.nextInt(),s.nextInt())?"ON":"OFF";
                o.println("Case #"+i+": "+answer);
             }
        } finally {
            s.close();
            o.close();
        }
    }

    
}
